﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.ServiceModel.Configuration;
using System.Text;
using ElectronicCommerce.Framework.Collections;
using ElectronicCommerce.Framework.ServiceModel.Resources;

namespace ElectronicCommerce.Framework.ServiceModel.Configuration
{
    /// <summary>
    /// 
    /// </summary>
    public static class ServiceAssertUtils
    {
        /// <summary>
        /// 基于serviceType的的Service配置校验。
        /// </summary>
        /// <param name="serviceElements"></param>
        /// <param name="serviceTypeName"></param>
        public static void ExistServiceInCollection(KeyedCollection<ServiceElement> serviceElements, Type serviceType)
        {
            if (serviceElements == null || serviceElements.Count <= 0)
            {
                throw new ConfigurationErrorsException(
                    string.Format(CultureInfo.InvariantCulture, R.ConfigError_ServiceNotFound, serviceType.FullName));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceElement"></param>
        /// <param name="serviceType"></param>
        public static void ServiceExists(ServiceElement serviceElement, Type serviceType)
        {
            ServiceExists(serviceElement, serviceType.FullName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceElement"></param>
        /// <param name="serviceName"></param>
        public static void ServiceExists(ServiceElement serviceElement, string serviceName)
        {
            if (serviceElement == null)
            {
                throw new ConfigurationErrorsException(
                    string.Format(CultureInfo.InvariantCulture, R.ConfigError_ServiceNotFound, serviceName));
            }
        }
    }
}
